import platform
import sys
from typing import Optional
from .base import BaseNotifier
import logging

logger = logging.getLogger(__name__)

class NotificationFactory:
    _instance: Optional[BaseNotifier] = None
    
    @classmethod
    def get_notifier(cls) -> BaseNotifier:
        """获取对应平台的通知实现（单例模式）"""
        if cls._instance is None:
            system = platform.system().lower()
            
            try:
                if system == 'darwin':
                    from .macos import MacOSNotifier
                    cls._instance = MacOSNotifier()
                elif system == 'win32':
                    from .windows import WindowsNotifier
                    cls._instance = WindowsNotifier()
                else:
                    from .windows import WindowsNotifier
                    cls._instance = WindowsNotifier()
                
                logger.info(f"Initialized notification system for {system}")
            except Exception as e:
                logger.error(f"Failed to initialize notifier: {str(e)}")
                raise RuntimeError(f"Failed to initialize notification system: {str(e)}")
                
        return cls._instance

# 简化调用
get_notifier = NotificationFactory.get_notifier 